<div id="export_tab">
    <?php if (!$model->packing_list): ?>
    <?php $this->beginClip('choosePacking');?>
        <div class="row buttons">
            Cargo needs to be in packing list, to be export. Click
    <?php
        $this->widget('zii.widgets.jui.CJuiButton', array(
            'name' => 'choose_packing',
            'caption' => 'Choose packing list',
            'value' => "packing",
            'htmlOptions'=>array('panel_id'=>'grid'),
        ));
    ?>
        to add this cargo to packing list.
    </div>
    <?php $this->endClip(); ?>
    <?php $this->beginClip('packingGrid'); ?>
    <?php
        $this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$packing->search(),
    'id'=>'packing_list_tab',
    'columns'=>array(
       	'date:date:Packing date',
        'ref:text:No.',
       	'handlingAgent.cname:text:Handling agent',
       	'notifyParty.cname:text:Consignee',
	'pol:text:Port of loading',
        'pod:text:Port of discharge',
        array(
            'class'=>'CLinkColumn',
            'label'=>'Add',
            'urlExpression'=>'CHtml::normalizeUrl(array("packing_list/addcargo","id"=>$data->id))',
            'linkHtmlOptions'=>array('id'=>'add_cargo'),
        )
    ),
));
?>

    <?php $this->endClip();?>
    <?php $this->widget('application.widgets.RiotingNerds.panel',
                array(
                    'id'=>'cargo-export-tab',
                    'panel'=>array(
                        'choose'=>$this->clips['choosePacking'],
                        'grid'=>$this->clips['packingGrid'],
	)));
    ?>
    <?php else:?>
        <?php
        $this->beginWidget('zii.widgets.CPortlet', array(
				'title'=>'Packing list information',
				'id'=>'packing_list',
			));
$this->widget('zii.widgets.CDetailView', array(
	'data'=>$model->packing_list,
	'attributes'=>array(
		'date:date:Date',
		'attn:text:Person in charge',
		'handlingAgent.cname:text:Handling agent',
		'clearingAgent.cname:text:Clearing agent',
		'notifyParty.cname:text:Notify party / Consignee',
		'shippingLine.cname:text:Carrier',
		'pol:text:Port of loading',
		'pod:text:Port of discharge',
        'subject:text:Subject / Topic',
	),
));
$this->endWidget();
?>
    <?php endif; ?>
<hr />
<?php if(!$model->export && $model->packing_list): ?>
    <div id="export_information">
        This cargo have no export information yet. Click
        <?php
        $this->widget('zii.widgets.jui.CJuiButton', array(
            'name' => 'choose_export',
            'caption' => 'Choose export',
            'value' => "export",
        ));
    ?>
        to add export information.
    </div>
<?php elseif($model->export): ?>

        <?php
        $this->beginWidget('zii.widgets.CPortlet', array(
				'title'=>'Export information',
				'id'=>'export_info',
			));
$this->widget('zii.widgets.CDetailView', array(
	'data'=>$model->export->export,
	'attributes'=>array(
		'etd:date:Departure date',
		'out_permit:text:Permit',
		'awb:text:Airway bill / Bill of loading',
		'vessel:text:Flight / Vessel',
		'mode:text:Mode of transport',
	),
));
$this->endWidget();
?>
<?php endif;?>
</div>


<?php
if(Yii::app()->request->enableCsrfValidation)
{
	$csrfTokenName = Yii::app()->request->csrfTokenName;
	$csrfToken = Yii::app()->request->csrfToken;
	$csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
}
else
	$csrf='';
$cs = Yii::app()->getClientScript();
$PackingURL = CHtml::normalizeUrl(array('packing_list/addcargo', 'cargo_id' => $model->id));
$ExportUrl = CHtml::normalizeUrl(array('export_information/list'));
$ExportUrl = CHtml::normalizeUrl(array('cargo/exporttab','id'=>$model->id));
$script = <<<EOD
$('input#choose_packing').click(function(){
    var original = $('#export_tab');
    $.winerdyPanel.MoveById('cargo-export-tab',$(this).attr('panel_id'));
	return false;
});
$('input#choose_export').click(function(){
    var original = $('#export_tab');
    $(original).detach();
    $('#export').subcontent({url:'$PackingURL',afterShow:function(){
            $('#export').append('<input name="cancel" id="cargo_cancel" type="button" value="Cancel" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false">');
            $('#cargo_cancel').click(function(){
                    $('#export').html($(original));
            });
    }});
});
$('#packing_list_tab a#add_cargo').live('click',function(){
    var ajaxOptions = {
        url:$(this).attr('href')+'?cargo_id=$model->id',
        $csrf
        success:function(data){
            $('#export').subcontent({url:'$ExportUrl',show:false});
            return;
        }
    };
    $.simplelogajax.ajax(ajaxOptions);
    return false;
});
EOD;
$cs->registerScript('cargo#export#tab', $script);
?>